"use strict";
cc._RF.push(module, 'dc72cElpc1BHpnyDh2UMQQh', 'JellyTween');
// eazax-ccc/components/tweens/JellyTween.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
/**
 * 果冻缓动效果
 * @see JellyTween.ts https://gitee.com/ifaswind/eazax-ccc/blob/master/components/tweens/JellyTween.ts
 */
var JellyTween = /** @class */ (function (_super) {
    __extends(JellyTween, _super);
    function JellyTween() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.frequency = 4;
        _this.decay = 2;
        _this.pressScale = 0.2;
        _this.totalTime = 1;
        _this.interval = 1;
        _this.playOnLoad = false;
        /** 原始缩放值 */
        _this.originalScale = 1;
        _this.tween = null;
        return _this;
    }
    JellyTween.prototype.start = function () {
        // 记录缩放值
        this.originalScale = this.node.scale;
        // 播放
        if (this.playOnLoad)
            this.play();
    };
    /**
     * 播放
     * @param repeatTimes 重复次数
     */
    JellyTween.prototype.play = function (repeatTimes) {
        var _this = this;
        // 重复次数
        var times = (repeatTimes != undefined && repeatTimes > 0) ? repeatTimes : 10e8;
        // 时长
        var pressTime = this.totalTime * 0.2; // 收缩时长
        var scaleBackTime = this.totalTime * 0.15; // 缩放至原始大小时长
        var bouncingTime = this.totalTime * 0.65; // 弹动时长
        // 振幅
        var amplitude = this.pressScale / scaleBackTime;
        // 播放
        this.tween = cc.tween(this.node)
            .repeat(times, cc.tween()
            .to(pressTime, { scaleX: this.originalScale + this.pressScale, scaleY: this.originalScale - this.pressScale }, { easing: 'sineOut' })
            .to(scaleBackTime, { scaleX: this.originalScale, scaleY: this.originalScale })
            .to(bouncingTime, {
            scaleX: {
                value: this.originalScale,
                progress: function (start, end, current, t) {
                    return end - _this.getDifference(amplitude, t);
                }
            },
            scaleY: {
                value: this.originalScale,
                progress: function (start, end, current, t) {
                    return end + _this.getDifference(amplitude, t);
                }
            }
        })
            .delay(this.interval))
            .start();
    };
    /**
     * 停止
     */
    JellyTween.prototype.stop = function () {
        this.tween && this.tween.stop();
        this.node.setScale(this.originalScale);
    };
    /**
     * 获取目标时刻弹性幅度
     * @param amplitude 幅度
     * @param time 时间
     */
    JellyTween.prototype.getDifference = function (amplitude, time) {
        // 角速度（ω=2nπ）
        var angularVelocity = this.frequency * Math.PI * 2;
        return amplitude * (Math.sin(time * angularVelocity) / Math.exp(this.decay * time) / angularVelocity);
    };
    __decorate([
        property({ tooltip: CC_DEV && '频率（弹跳次数）' })
    ], JellyTween.prototype, "frequency", void 0);
    __decorate([
        property({ tooltip: CC_DEV && '衰退指数' })
    ], JellyTween.prototype, "decay", void 0);
    __decorate([
        property({ tooltip: CC_DEV && '下压缩放' })
    ], JellyTween.prototype, "pressScale", void 0);
    __decorate([
        property({ tooltip: CC_DEV && '效果总时长' })
    ], JellyTween.prototype, "totalTime", void 0);
    __decorate([
        property({ tooltip: CC_DEV && '播放间隔' })
    ], JellyTween.prototype, "interval", void 0);
    __decorate([
        property({ tooltip: CC_DEV && '自动播放' })
    ], JellyTween.prototype, "playOnLoad", void 0);
    JellyTween = __decorate([
        ccclass
    ], JellyTween);
    return JellyTween;
}(cc.Component));
exports.default = JellyTween;

cc._RF.pop();